/***************************************************************************
 *   Copyright (C) 2008 by Eduardo Gurgel Pinho                            *
 *   edgurgel@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef __PHOTON_MAP_H__
#define __PHOTON_MAP_H__

#include <vector>
#include "object/object.h"
#include "common/color.h"
#include "math/vector.h"
#include "math/ray.h"
#include "photon.h"
#include "kd_tree.h"

namespace Sirat {

namespace Photon_Mapping {

class Photontracer;

class Photon_Map{	
public:
	Photon_Map();
	~Photon_Map();
	
	void insert(Photon*);
	void scale(const double);
	int get_size(void);
	void clear(void);
	
	Kd_Tree* get_kd_tree(void) const;
	void destroy_kd_tree(void);
	Kd_Tree* construct_kd_tree_rec(void);
	Common::Color irradiance_estimate(Object::Object* _object,const Math::Ray& _ray,const Math::Vector& _point,const unsigned int _sample_photons) const;
	
	Photontracer* photontracer;
private:
	Kd_Node* construct_kd_tree(std::vector<Photon*>&,unsigned int);
	std::vector<Photon*>::iterator choose_pivot(std::vector<Photon*>&,std::vector<Photon*>&,std::vector<Photon*>&);
	
	std::vector<Photon*> photon_list;
	Kd_Tree* kd_tree;

};

}

}
#endif
